fix(jsx): correct source location when react-jsx and whitespace before jsx#61534
fix(jsx): correct source location when react-jsx and whitespace before jsx#61534jakebailey merged 3 commits intomicrosoft:mainfrom
Conversation
|
I've applied the same fix for fragments as well, as they seemed to use the same pattern for source location handling. |
ffaf949 to
484a445
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect source location information in JSX transformation when using react-jsx mode with whitespace before JSX elements. The issue was that the code was using node.pos (which includes leading trivia) instead of node.getStart() (which excludes leading trivia), causing column numbers in generated code to be off by the amount of leading whitespace.
Key changes:
- Updated
visitJsxElement,visitJsxSelfClosingElement, andvisitJsxFragmentfunctions to usegetTokenPosOfNode()for accurate source location - All test baselines now show corrected column numbers that match Babel's output
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/compiler/transformers/jsx.ts | Modified JSX visitor functions to use getTokenPosOfNode() for correct source locations |
| tests/baselines/reference/tsxReactEmit8(jsx=react-jsxdev).js | Updated baseline with corrected line and column numbers |
| tests/baselines/reference/reactImportUnusedInNewJSXEmit(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxRuntimePragma(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxNamespaceNoElementChildrenAttributeReactJsx(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxNamespaceElementChildrenAttributeIgnoredWhenReactJsx(jsx=react-jsxdev).js | Updated baseline with corrected line and column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformSubstitutesNamesFragment(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformSubstitutesNames(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformNestedSelfClosingChild(jsx=react-jsxdev).js | Updated baseline with corrected line and column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformKeyPropCustomImportPragma(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformKeyPropCustomImport(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformKeyProp(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxJsxsCjsTransformChildren(jsx=react-jsxdev).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/jsxEmptyExpressionNotCountedAsChild(jsx=react-jsxdev).js | Updated baseline with corrected line and column numbers |
| tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=legacy).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=force).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=system,moduledetection=auto).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=legacy).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=force).js | Updated baseline with corrected column numbers |
| tests/baselines/reference/commentsOnJSXExpressionsArePreserved(jsx=react-jsxdev,module=commonjs,moduledetection=auto).js | Updated baseline with corrected column numbers |
54739ab to
fe90a2f
Compare
|
rebased to latest EDIT: and again, as |
fe90a2f to
3539c8b
Compare
…e jsx fixes microsoft#61533 the code seemed to be using `node.pos` (`node.getFullStart()`) instead of `node.getStart()`, which caused the source location to be off. now baselines match babel's output (which seems correct). not sure about using `getTokenPosOfNode()` (used by `getStart()`), but didn't find any better way to do things internally.
3539c8b to
90f16db
Compare
|
LGTM but I would switch to |
per PR review
|
Thank you. Been waiting for a while for this one to get in. |
|
Yes, there's a board, and Copilot is good at porting these. We have yet to start targeting 6.0 in the Go code, though, but that will happen ~today |
the code seemed to be using
node.pos(node.getFullStart()) instead ofnode.getStart(), which caused the source location to be off.now baselines match babel's output (which seems correct).
not sure about using
getTokenPosOfNode()(used bygetStart()), but didn't find any better way to do things internally.fixes #61533